<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;

class DiscountPay2
{
    protected $id;

    public function __construct($id, $product_type, $title)
    {
        $this->id = $id;
        $this->product_type = $product_type;
        $this->title = $title;
    }

    protected function script()
    {
        return <<<SCRIPT

layui.use('layer', function(){
        var layer = layui.layer;
        $('.dispay').click(function () {
           var that = this;
           var id = $(that).attr('data-id');
           var product_type = $(that).attr('data-type');
           var title = $(that).attr('data-title');
           if(product_type == 2){
             var index = layer.open({
                   type: 2,
                   title: title,
                   content: '/admin/common/order/divide/discountpay?oid='+id,
                   area: ['50%', '50%'],
                   btn: ['确定', '取消'],
                   yes: function(index, layero){
                       layer.close(index);
                   }
             });
             return;
           }
           var index = layer.open({
               type: 2,
               content: '/html/admin/repayment.html?id='+id,
               area: ['500px', '250px'],
               yes: function(index, layero){
                   layer.close(index);
               }
           });

       });

    });

SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());

        return "&nbsp;<a href='javascript:void(0);'><button data-title='{$this->title}' data-id='{$this->id}' data-type='{$this->product_type}' class='dispay layui-btn layui-btn-danger layui-btn-xs'>扣</button></a>";

    }

    public function __toString()
    {
        return $this->render();
    }
}